package state;


import state.bean.Rect;

public class Clip extends Rect {
  public Clip(int x, int y, int width, int height) {
    super(x, y, width, height);
  }
  
  public static Clip getClip(Graphics g) {
    return new Clip(g.getClipX(), g.getClipY(), g.getClipWidth(), g.getClipHeight());
  }
  
  public static void getClip(Graphics g, Clip reuseClip) {
    reuseClip.set(g.getClipX(), g.getClipY(), g.getClipWidth(), g.getClipHeight());
  }
  
  public static void setClip(Graphics g, Clip clip) {
    g.setClip(clip.x, clip.y, clip.width, clip.height);
  }
  
  public void set(int x, int y, int width, int height) {
    this.x = x;
    this.y = y;
    this.width = width;
    this.height = height;
  }
  
  public void clipRect(Graphics g) {
    g.clipRect(x, y, width, height);
  }
  
  public void applyClip(Graphics g) {
    setClip(g, this);
  }
  
  public void clipRect(Graphics g, int clipX, int clipY, int clipWidth, int clipHeight) {
    applyClip(g);
    g.clipRect(clipX, clipY, clipWidth, clipHeight);
  }
  
  public void clipRect(Graphics g, Clip clip) {
    applyClip(g);
    clip.clipRect(g);
  }
}
